/***********************************************
 **** 版权声明处 **
 ****  为了方便阅读和维护，请严格遵守相关代码规范，谢谢   ****
 *******************************************/
package com.bingya.service.model
{
	/*******************************************
	 **** huangjixin,2012-6-8,上午10:45:14 **
	 **** 请一句话表述该类主要作用  **
	 *******************************************/
	import com.bingya.service.common.Global;
	import com.bingya.service.common.Page;
	import com.bingya.service.model.business.system.UserServiceDelegate;
	import com.bingya.service.model.vo.User;
	
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import mx.controls.Alert;
	import mx.messaging.Channel;
	import mx.messaging.ChannelSet;
	import mx.messaging.channels.AMFChannel;
	import mx.rpc.AsyncToken;
	import mx.rpc.Responder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	public class UserServiceRemoteProxy extends EventDispatcher
	{
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// private 类私有静态变量和静态常量声明处。（全部大写，使用下划线进行分割）
		// 例如：private static const EXAMPLE:String = "example";
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// public 类公有静态变量和静态常量声明处。（全部大写，使用下划线进行分割）
		// 例如：public static const EXAMPLE:String = "example";
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		
		
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// private 私有变量声明处，请以“_”开头定义变量
		// 例如：private var _example:String;
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		
		
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// public 公有变量声明处
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		
		
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// 构造函数，初始化相关工作可以放在里面
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		public function UserServiceRemoteProxy(target:IEventDispatcher=null)
		{
			//TODO: implement function
			super(target);
		}//构造函数结束
		
		
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// getter和setter函数
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		
		
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// 相关事件响应函数和逻辑函数存放处
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		public function deleteByPrimaryKey(id:int):void  
		{  
			var delegate:UserServiceDelegate = new UserServiceDelegate(new Responder(onDeleteByPrimaryKeyResult, onFault));  
			delegate.deleteByPrimaryKey(id);  
		}  
		
		private function onDeleteByPrimaryKeyResult(pResultEvt:ResultEvent):void  
		{  
			var result:int=pResultEvt.result as int ;  
			//sendNotification();  
		}  
		
		public function insert(entity:User):void  
		{  
			var delegate:UserServiceDelegate = new UserServiceDelegate(new Responder(onInsertResult, onFault));  
			delegate.insert(entity);  
		}  
		
		private function onInsertResult(pResultEvt:ResultEvent):void  
		{  
			var result:int=pResultEvt.result as int ;  
			//sendNotification();  
		}  
		
		public function selectAll():void  
		{  
			var delegate:UserServiceDelegate = new UserServiceDelegate(new Responder(onSelectAllResult, onFault));  
			delegate.selectAll();  
		}  
		
		private function onSelectAllResult(pResultEvt:ResultEvent):void  
		{  
			var result:Array=pResultEvt.result as Array ;  
			//sendNotification();  
		}  
		
		public function selectByPrimaryKey(id:int):void  
		{  
			var delegate:UserServiceDelegate = new UserServiceDelegate(new Responder(onSelectByPrimaryKeyResult, onFault));  
			delegate.selectByPrimaryKey(id);  
		}  
		
		private function onSelectByPrimaryKeyResult(pResultEvt:ResultEvent):void  
		{  
			var result:Object=pResultEvt.result;  
			//sendNotification();  
		}  
		
		public function update(entity:User):void  
		{  
			var delegate:UserServiceDelegate = new UserServiceDelegate(new Responder(onUpdateResult, onFault));  
			delegate.update(entity);  
		}  
		
		private function onUpdateResult(pResultEvt:ResultEvent):void  
		{  
			var result:int=pResultEvt.result as int ;  
			//sendNotification();  
		}  
		
		public function findPage(page:Page):void  
		{  
			var delegate:UserServiceDelegate = new UserServiceDelegate(new Responder(onFindPageResult, onFault));  
			delegate.findPage(page);  
		}  
		
		private function onFindPageResult(pResultEvt:ResultEvent):void  
		{  
			var result:Page=pResultEvt.result as Page ;  
			//sendNotification();  
		}  
		
		public function login(username:String, password:String):void  
		{   
			if(!Global.getInstance().loginChannelSet){
				var channel:AMFChannel = new AMFChannel();
				channel.uri = Global.getInstance().endPoint;
				var channelSet:ChannelSet = new ChannelSet();
				channelSet.addChannel(channel);
				Global.getInstance().loginChannelSet = channelSet;
			}
			var token:AsyncToken = Global.getInstance().loginChannelSet.login(username,password);
			token.addResponder( new Responder(onLoginResult,onLoginFault));
		}  
		
		private function onLoginResult(pResultEvt:ResultEvent):void  
		{  
			var result:Object=pResultEvt.result as Object ;  
			//sendNotification();  
		}  
		
		private function onLoginFault(pFaultEvt:FaultEvent):void  
		{  
			Alert.show(pFaultEvt.fault.faultString, '登录失败');  
		}  
		
		
		public function logout():void  
		{   
			if(!Global.getInstance().loginChannelSet){
				var channel:AMFChannel = new AMFChannel();
				channel.uri = Global.getInstance().endPoint;
				var channelSet:ChannelSet = new ChannelSet();
				channelSet.addChannel(channel);
				Global.getInstance().loginChannelSet = channelSet;
			}
			var token:AsyncToken = Global.getInstance().loginChannelSet.logout();
			token.addResponder( new Responder(onLogoutResult,onLogoutFault));
		}  
		
		private function onLogoutResult(pResultEvt:ResultEvent):void  
		{  
			var result:Object=pResultEvt.result as Object ;  
			//sendNotification();  
		}  
		
		private function onLogoutFault(pFaultEvt:FaultEvent):void  
		{  
			Alert.show(pFaultEvt.fault.faultString, '登录失败');  
		}  
		
		
		
		private function onFault(pFaultEvt:FaultEvent):void  
		{  
			Alert.show(pFaultEvt.fault.faultString, 'Error');  
		}  
		
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// override 覆盖函数
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
	}//类结束
}//包结束